package com.job.dao;

import com.job.pojo.Check;
import com.job.pojo.Count;
import com.job.pojo.Money;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CheckDao {

    //查询：
    //1.查询所有员工考勤记录
    @Select("select * from userCheck ")
    List<Check> selectAll();
    //2.按id查询
    @Select("select * from userCheck where userId=#{userId}")
    List<Check>selectById(Check check);
    //3.按姓名查询
    @Select("select * from userCheck where userName=#{userName}")
    List<Check>selectByName(Check check);
    //4.按类型查询
    @Select("select * from userCheck where type=#{type}")
    List<Check>selectByType(Check check);
    @Select("select * from userCheck where type=#{type} and userId=#{userId}")
    List<Check>selectByTypeId(Check check);
    @Select("select * from userCheck where type=#{type} and userName=#{userName}")
    List<Check>selectByTypeName(Check check);

    //5.查询时间

    @Select({"select distinct (time)from userCheck"})
    List<Check> selectTime();
    @Select({"select count(*) from userCheck where type=#{type} "})
    int selectCount(Check check);

    //6.查询员工工资
    @Select("select * from userMoney where userId=#{userId}and userName=#{userName}")
    List<Money>selectMyMoney(Money money);
    @Select("select * from userMoney ")
    List<Money>selectAllMoney(Money money);

    //7.查询奖金最高：
    @Select("select * from userMoney order by addMoney desc limit 3")
    List<Money>countAdd(Money money);
    //罚款最高
    @Select("select * from userMoney order by punishMoney desc limit 3")
    List<Money>countPunish(Money money);


    //增加申请（插入）
    @Insert("insert into userCheck(userName,userId,type,time,isHandle)value(#{userName},#{userId},#{type},#{time},#{isHandle})")
    int apply(Check check);
    //增加工资：
    @Insert("insert into userMoney(userName,userId,addMoney,punishMoney,basicMoney,meritMoney,totalMoney,moneyTime)" +
            "value(#{userName},#{userId},#{addMoney},#{punishMoney},#{basicMoney},#{meritMoney},#{totalMoney},#{moneyTime})")
    int add(Money money);



    //修改工资：

    @Update("update userMoney set basicMoney=#{basicMoney},meritMoney=#{meritMoney},addMoney=#{addMoney},punishMoney=#{punishMoney},totalMoney=#{totalMoney}" +
            " where userId=#{userId}and moneyTime=#{moneyTime}")
    int updateMoney(Money money);


    //删除工资：
    @Delete("delete from userMoney where userId=#{userId} and moneyTime=#{moneyTime}")
    int delUser(Money money);



}
